<template>
  <div class="assess_form neurorehabilitation">
    <div class="form_title">XXXX医疗机构</div>
    <div class="form_name">神经康复综合评定表</div>
    <div class="form_patient_bar">
      <div v-for="(item, index) in patientStruct" :key="index" class="patient_info_item">
        <div class="item_label">{{ item.label }}：</div>
        <div class="item_value">{{ formType == 'template' ? item.label : patientInfo[item.key] }}{{ item.unit }}</div>
      </div>
    </div>
    <div class="form_diagnosis">
      <div class="diagnosis_label">诊断：</div>
      <div class="diagnosis_value">{{ formType == 'template' ? '诊断' : selfFormData.diagnosticInfo }}</div>
    </div>
    <el-form ref="assessForm" :model="selfFormData" :rules="rules">
      <el-form-item class="assess_term" prop="estimateType">
        <el-radio-group v-if="formType !== 'view'" v-model="selfFormData.estimateType" :disabled="formType == 'template'">
          <el-radio :label="1" :disabled="!!selfFormData.evaluateUser1">
            <div class="term_item">
              <div class="term_name">初期评定</div>
              <div class="term_time">评定时间：{{ selfFormData.estimateType === 1 ? selfFormData.evaluateTime : (selfFormData.evaluateTime1 ? selfFormData.evaluateTime1 : '') }}</div>
              <div class="term_sign">签名：{{ selfFormData.estimateType === 1 ? selfFormData.evaluateUser : (selfFormData.evaluateUser1 ? selfFormData.evaluateUser1 : '') }}</div>
            </div>
          </el-radio>
          <el-radio :label="2" :disabled="!!selfFormData.evaluateUser2">
            <div class="term_item">
              <div class="term_name">中期评定</div>
              <div class="term_time">评定时间：{{ selfFormData.estimateType === 2 ? selfFormData.evaluateTime : (selfFormData.evaluateTime2 ? selfFormData.evaluateTime2 : '') }}</div>
              <div class="term_sign">签名：{{ selfFormData.estimateType === 2 ? selfFormData.evaluateUser : (selfFormData.evaluateUser2 ? selfFormData.evaluateUser2 : '') }}</div>
            </div>
          </el-radio>
          <el-radio :label="3" :disabled="!!selfFormData.evaluateUser3">
            <div class="term_item">
              <div class="term_name">出院前评定</div>
              <div class="term_time">评定时间：{{ selfFormData.estimateType === 3 ? selfFormData.evaluateTime : (selfFormData.evaluateTime3 ? selfFormData.evaluateTime3 : '') }}</div>
              <div class="term_sign">签名：{{ selfFormData.estimateType === 3 ? selfFormData.evaluateUser : (selfFormData.evaluateUser3 ? selfFormData.evaluateUser3 : '') }}</div>
            </div>
          </el-radio>
        </el-radio-group>
        <div v-else class="assess_term">
          <div class="term_item">
            <div class="term_name">初期评定</div>
            <div class="term_time">评定时间：{{ selfFormData.evaluateTime1 }}</div>
            <div class="term_sign">签名：{{ selfFormData.evaluateUser1 }}</div>
          </div>
          <div class="term_item">
            <div class="term_name">中期评定</div>
            <div class="term_time">评定时间：{{ selfFormData.evaluateTime2 }}</div>
            <div class="term_sign">签名：{{ selfFormData.evaluateUser2 }}</div>
          </div>
          <div class="term_item">
            <div class="term_name">出院前评定</div>
            <div class="term_time">评定时间：{{ selfFormData.evaluateTime3 }}</div>
            <div class="term_sign">签名：{{ selfFormData.evaluateUser3 }}</div>
          </div>
        </div>
      </el-form-item>
      <el-form-item v-if="formType === 'edit' || formType === 'template'" label="布氏分级评定：" prop="bruseType">
        <el-radio-group v-model="selfFormData.bruseType" :disabled="!firstAssess || formType === 'template'">
          <el-radio v-for="(option, index) in typeList" :key="'option1_' + index" :label="option.value">{{ option.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item prop="brunnstrom">
        <table border class="form_table">
          <colgroup>
            <col style="width: 120px;">
            <col style="width: 110px;">
            <col v-if="formType !== 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
          </colgroup>
          <thead>
            <tr>
              <th class="text_center" />
              <th class="text_center">{{ getLabelByValue(typeList, selfFormData.bruseType) }}</th>
              <th v-if="formType !== 'view'" class="text_center">评估</th>
              <th v-if="formType === 'view'" class="text_center">初评</th>
              <th v-if="formType === 'view'" class="text_center">中评</th>
              <th v-if="formType === 'view'" class="text_center">末评</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in assessFormStruct4" :key="'assess4_' + index">
              <td v-if="item.rowspan > 0" class="text_center" :rowspan="item.rowspan" :colspan="item.subProject ? 1 : 2">{{ item.project }}</td>
              <td v-if="item.subProject">{{ item.subProject }}</td>
              <td v-if="formType === 'edit' || formType === 'template'" :class="{text_center: item.controlType === 'input'}">
                <el-radio-group v-if="item.controlType === 'radio'" v-model="selfFormData[item.projectKey][item.editKey]" class="score_radio" :disabled="formType === 'template'">
                  <el-radio v-for="(option, opIndex) in item.options" :key="'option_' + index + '_' + opIndex" :label="option.value">{{ option.label }}</el-radio>
                </el-radio-group>
                <el-input-number v-else-if="item.controlType === 'input'" v-model="selfFormData[item.projectKey][item.editKey]" :min="item.min" :max="item.max" controls-position="right" @input="calcTotal" :disabled="formType === 'template'"/>
                <span v-else>{{ selfFormData[item.projectKey][item.editKey] }}</span>
              </td>
              <td v-if="formType === 'view'" class="text_center">{{ item.controlType === 'radio' ? getLabelByValue(item.options, selfFormData[item.projectKey][item.firstKey]) : selfFormData[item.projectKey][item.firstKey] }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ item.controlType === 'radio' ? getLabelByValue(item.options, selfFormData[item.projectKey][item.midKey]) : selfFormData[item.projectKey][item.midKey] }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ item.controlType === 'radio' ? getLabelByValue(item.options, selfFormData[item.projectKey][item.lastKey]) : selfFormData[item.projectKey][item.lastKey] }}</td>
            </tr>
          </tbody>
        </table>
      </el-form-item>
      <div>1.肌张力检测（改良Ashworth）：</div>
      <el-form-item v-if="formType === 'edit' || formType === 'template'" label="检测侧：" prop="tensionType">
        <el-radio-group v-model="selfFormData.tensionType" :disabled="!firstAssess || formType === 'template'">
          <el-radio v-for="(option, index) in typeList" :key="'option1_' + index" :label="option.value">{{ option.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item prop="ashworth">
        <table border class="form_table">
          <colgroup>
            <col style="width: 140px;">
            <col v-if="formType !== 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col style="width: 140px;">
            <col v-if="formType !== 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
          </colgroup>
          <thead>
            <tr>
              <th class="text_center">{{ getLabelByValue(typeList, selfFormData.tensionType) }}</th>
              <th v-if="formType !== 'view'" class="text_center">评估</th>
              <th v-if="formType === 'view'" class="text_center">初评</th>
              <th v-if="formType === 'view'" class="text_center">中评</th>
              <th v-if="formType === 'view'" class="text_center">末评</th>
              <th class="text_center">{{ getLabelByValue(typeList, selfFormData.tensionType) }}</th>
              <th v-if="formType !== 'view'" class="text_center">评估</th>
              <th v-if="formType === 'view'" class="text_center">初评</th>
              <th v-if="formType === 'view'" class="text_center">中评</th>
              <th v-if="formType === 'view'" class="text_center">末评</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="index in 4" :key="'assess1_' + index">
              <td class="text_center">{{ assessFormStruct1[index - 1].content }}</td>
              <td v-if="formType === 'edit' || formType === 'template'">
                <el-radio-group v-model="selfFormData.ashworth[assessFormStruct1[index - 1].editKey]" class="score_radio" :disabled="formType === 'template'">
                  <el-radio v-for="(option, optionIndex) in tensionValueList" :key="'tension' + (index - 1) + '_' + optionIndex" :label="option.value">{{ option.label }}</el-radio>
                </el-radio-group>
              </td>
              <td v-if="formType === 'view'" class="text_center">{{ getLabelByValue(tensionValueList, selfFormData.ashworth[assessFormStruct1[index - 1].firstKey]) }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ getLabelByValue(tensionValueList, selfFormData.ashworth[assessFormStruct1[index - 1].midKey]) }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ getLabelByValue(tensionValueList, selfFormData.ashworth[assessFormStruct1[index - 1].lastKey]) }}</td>
              <td class="text_center">{{ assessFormStruct1[index + 3].content }}</td>
              <td v-if="formType === 'edit' || formType === 'template'">
                <el-radio-group v-model="selfFormData.ashworth[assessFormStruct1[index + 3].editKey]" class="score_radio" :disabled="formType === 'template'">
                  <el-radio v-for="(option, optionIndex) in tensionValueList" :key="'tension' + (index + 3) + '_' + optionIndex" :label="option.value">{{ option.label }}</el-radio>
                </el-radio-group>
              </td>
              <td v-if="formType === 'view'" class="text_center">{{ getLabelByValue(tensionValueList, selfFormData.ashworth[assessFormStruct1[index + 3].firstKey]) }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ getLabelByValue(tensionValueList, selfFormData.ashworth[assessFormStruct1[index + 3].midKey]) }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ getLabelByValue(tensionValueList, selfFormData.ashworth[assessFormStruct1[index + 3].lastKey]) }}</td>
            </tr>
          </tbody>
        </table>
      </el-form-item>
      <div>2.徒手肌力检测（MMT）：</div>
      <el-form-item v-if="formType === 'edit' || formType === 'template'" label="检测侧：" prop="unarmedType">
        <el-radio-group v-model="selfFormData.unarmedType" :disabled="!firstAssess || formType === 'template'">
          <el-radio v-for="(option, index) in typeList" :key="'option2_' + index" :label="option.value">{{ option.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item prop="mmt">
        <table border class="form_table">
          <colgroup>
            <col style="width: 50px;">
            <col style="width: 90px;">
            <col v-if="formType !== 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col style="width: 50px;">
            <col style="width: 90px;">
            <col v-if="formType !== 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
          </colgroup>
          <thead>
            <tr>
              <th class="text_center">{{ getLabelByValue(typeList, selfFormData.unarmedType) }}</th>
              <th class="text_center">动作</th>
              <th v-if="formType !== 'view'" class="text_center">评估</th>
              <th v-if="formType === 'view'" class="text_center">初评</th>
              <th v-if="formType === 'view'" class="text_center">中评</th>
              <th v-if="formType === 'view'" class="text_center">末评</th>
              <th class="text_center">{{ getLabelByValue(typeList, selfFormData.unarmedType) }}</th>
              <th class="text_center">动作</th>
              <th v-if="formType !== 'view'" class="text_center">评估</th>
              <th v-if="formType === 'view'" class="text_center">初评</th>
              <th v-if="formType === 'view'" class="text_center">中评</th>
              <th v-if="formType === 'view'" class="text_center">末评</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="index in 12" :key="'assess2_' + index">
              <td v-if="!assessFormStruct2[index - 1] || assessFormStruct2[index - 1].rowspan > 0" class="text_center" :rowspan="assessFormStruct2[index - 1] ? assessFormStruct2[index - 1].rowspan : 1">{{ assessFormStruct2[index - 1] ? assessFormStruct2[index - 1].part : '' }}</td>
              <td class="text_center">{{ assessFormStruct2[index - 1] ? assessFormStruct2[index - 1].content : '' }}</td>
              <td v-if="formType === 'edit' || formType === 'template'">
                <el-radio-group v-if="assessFormStruct2[index - 1]" v-model="selfFormData.mmt[assessFormStruct2[index - 1].editKey]" class="score_radio" :disabled="formType === 'template'">
                  <el-radio v-for="(option, optionIndex) in unarmedValueList" :key="'unarmed' + (index - 1) + '_' + optionIndex" :label="option.value">{{ option.label }}</el-radio>
                </el-radio-group>
                <span v-else />
              </td>
              <td v-if="formType === 'view'" class="text_center">{{ assessFormStruct2[index - 1] ? getLabelByValue(unarmedValueList, selfFormData.mmt[assessFormStruct2[index - 1].firstKey]) : '' }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ assessFormStruct2[index - 1] ? getLabelByValue(unarmedValueList, selfFormData.mmt[assessFormStruct2[index - 1].midKey]) : '' }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ assessFormStruct2[index - 1] ? getLabelByValue(unarmedValueList, selfFormData.mmt[assessFormStruct2[index - 1].lastKey]) : '' }}</td>
              <td v-if="!assessFormStruct2[index + 11] || assessFormStruct2[index + 11].rowspan > 0" class="text_center" :rowspan="assessFormStruct2[index + 11] ? assessFormStruct2[index + 11].rowspan : 1">{{ assessFormStruct2[index + 11] ? assessFormStruct2[index + 11].part : '' }}</td>
              <td class="text_center">{{ assessFormStruct2[index + 11] ? assessFormStruct2[index + 11].content : '' }}</td>
              <td v-if="formType === 'edit' || formType === 'template'">
                <el-radio-group v-if="assessFormStruct2[index + 11]" v-model="selfFormData.mmt[assessFormStruct2[index + 11].editKey]" class="score_radio" :disabled="formType === 'template'">
                  <el-radio v-for="(option, optionIndex) in unarmedValueList" :key="'unarmed' + (index + 11) + '_' + optionIndex" :label="option.value">{{ option.label }}</el-radio>
                </el-radio-group>
                <span v-else />
              </td>
              <td v-if="formType === 'view'" class="text_center">{{ assessFormStruct2[index + 11] ? getLabelByValue(unarmedValueList, selfFormData.mmt[assessFormStruct2[index + 11].firstKey]) : '' }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ assessFormStruct2[index + 11] ? getLabelByValue(unarmedValueList, selfFormData.mmt[assessFormStruct2[index + 11].midKey]) : '' }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ assessFormStruct2[index + 11] ? getLabelByValue(unarmedValueList, selfFormData.mmt[assessFormStruct2[index + 11].lastKey]) : '' }}</td>
            </tr>
          </tbody>
        </table>
      </el-form-item>
      <div>3.关节活动度：</div>
      <el-form-item prop="rom">
        <table border class="form_table">
          <colgroup>
            <col v-if="formType !== 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col style="width: 70px;">
            <col style="width: 115px;">
            <col style="width: 120px;">
            <col v-if="formType !== 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
            <col v-if="formType === 'view'">
          </colgroup>
          <thead>
            <tr>
              <th class="text_center" :colspan="formType === 'view' ? 3 : 1">左侧</th>
              <th class="text_center" :rowspan="formType === 'view' ? 2 : 1">部位</th>
              <th class="text_center" :rowspan="formType === 'view' ? 2 : 1">动作</th>
              <th class="text_center" :rowspan="formType === 'view' ? 2 : 1">活动度</th>
              <th class="text_center" :colspan="formType === 'view' ? 3 : 1">右侧</th>
            </tr>
            <tr v-if="formType === 'view'">
              <th class="text_center">初评</th>
              <th class="text_center">中评</th>
              <th class="text_center">末评</th>
              <th class="text_center">初评</th>
              <th class="text_center">中评</th>
              <th class="text_center">末评</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item, index) in assessFormStruct3" :key="'assess3_' + index">
              <td v-if="formType === 'edit' || formType === 'template'">
                <el-input :class="{valid_input: isValidateItem(index, 'left')}" v-model="selfFormData.rom[item.leftEditKey]" :placeholder="item.levelValue" :disabled="formType === 'template'"/>
              </td>
              <td v-if="formType === 'view'" class="text_center">{{ selfFormData.rom[item.leftFirstKey] }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ selfFormData.rom[item.leftMidKey] }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ selfFormData.rom[item.leftLastKey] }}</td>
              <td v-if="item.rowspan > 0" class="text_center" :rowspan="item.rowspan">{{ item.part }}</td>
              <td class="text_center">{{ item.content }}</td>
              <td class="text_center">{{ item.levelValue }}</td>
              <td v-if="formType === 'edit' || formType === 'template'">
                <el-input :class="{valid_input: isValidateItem(index, 'right')}" v-model="selfFormData.rom[item.rightEditKey]" :placeholder="item.levelValue" :disabled="formType === 'template'"/>
              </td>
              <td v-if="formType === 'view'" class="text_center">{{ selfFormData.rom[item.rightFirstKey] }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ selfFormData.rom[item.rightMidKey] }}</td>
              <td v-if="formType === 'view'" class="text_center">{{ selfFormData.rom[item.rightLastKey] }}</td>
            </tr>
          </tbody>
        </table>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import moment from 'moment'
const initFormItemData = (length, defaultValue) => {
  const data = {}
  for (let index = 1; index <= length; index++) {
    data['item' + index] = defaultValue
  }
  return data
}

const initDefaultForm = () => {
  const rom = {}
  for (let romIndex = 1; romIndex <= 12; romIndex++) {
    rom['leftItem' + romIndex] = ''
    rom['rightItem' + romIndex] = ''
  }
  return {
    estimateType: undefined,
    tensionType: undefined,
    unarmedType: undefined,
    bruseType: undefined,
    ashworth: initFormItemData(8),
    mmt: initFormItemData(20),
    rom,
    brunnstrom: initFormItemData(3),
    walking: initFormItemData(1),
    language: initFormItemData(1),
    drinking: initFormItemData(1),
    hand: initFormItemData(1),
    sitting: initFormItemData(1),
    standing: initFormItemData(1),
    mrs: initFormItemData(1),
    mas: initFormItemData(8),
    barthel: initFormItemData(10),
    mmse: initFormItemData(10),
    evaluateUser: '',
    evaluateTime: ''
  }
}
const typeList = [
  {
    label: '左侧',
    value: 1
  },
  {
    label: '右侧',
    value: 2
  },
  {
    label: '双侧',
    value: 3
  }
]
const tensionValueList = [
  {
    label: '0级',
    value: 0
  },
  {
    label: '1级',
    value: 1
  },
  {
    label: '1+级',
    value: 2
  },
  {
    label: '2级',
    value: 3
  },
  {
    label: '3级',
    value: 4
  },
  {
    label: '4级',
    value: 5
  }
]
const unarmedValueList = [
  {
    label: '0级',
    value: 0
  },
  {
    label: '1级',
    value: 1
  },
  {
    label: '2级',
    value: 2
  },
  {
    label: '3级',
    value: 3
  },
  {
    label: '4级',
    value: 4
  },
  {
    label: '5级',
    value: 5
  }
]
const brunnstromTypeList = [
  {
    label: 'Ⅰ',
    value: 1
  },
  {
    label: 'Ⅱ',
    value: 2
  },
  {
    label: 'Ⅲ',
    value: 3
  },
  {
    label: 'Ⅳ',
    value: 4
  },
  {
    label: 'Ⅴ',
    value: 5
  },
  {
    label: 'Ⅵ',
    value: 6
  }
]
const zeroToSixList = [
  {
    label: '0级',
    value: 0
  },
  {
    label: '1级',
    value: 1
  },
  {
    label: '2级',
    value: 2
  },
  {
    label: '3级',
    value: 3
  },
  {
    label: '4级',
    value: 4
  },
  {
    label: '5级',
    value: 5
  },
  {
    label: '6级',
    value: 6
  }
]
const handTypeList = [
  {
    label: 'Ⅰ级（失用手）',
    value: 1
  },
  {
    label: 'Ⅱ级（辅助手C）',
    value: 2
  },
  {
    label: 'Ⅲ级（辅助手B）',
    value: 3
  },
  {
    label: 'Ⅳ级（辅助手A）',
    value: 4
  },
  {
    label: 'Ⅴ级（实用手B）',
    value: 5
  },
  {
    label: 'Ⅵ级（实用手A）',
    value: 6
  }
]
const sittingTypeList = [
  {
    label: '坐位0级',
    value: 0
  },
  {
    label: '坐位1级',
    value: 1
  },
  {
    label: '坐位2级',
    value: 2
  },
  {
    label: '坐位3级',
    value: 3
  },
  {
    label: '坐位4级',
    value: 4
  },
  {
    label: '坐位5级',
    value: 5
  }
]
const standingTypeList = [
  {
    label: '立位0级',
    value: 0
  },
  {
    label: '立位1级',
    value: 1
  },
  {
    label: '立位2级',
    value: 2
  },
  {
    label: '立位3级',
    value: 3
  },
  {
    label: '立位4级',
    value: 4
  },
  {
    label: '立位5级',
    value: 5
  }
]
const assessFormStruct1 = [
  {
    content: '肩：屈/伸',
    editKey: 'item1',
    firstKey: 'firstAshworthItem1',
    midKey: 'midAshworthItem1',
    lastKey: 'lastAshworthItem1'
  },
  {
    content: '肘：屈/伸',
    editKey: 'item2',
    firstKey: 'firstAshworthItem2',
    midKey: 'midAshworthItem2',
    lastKey: 'lastAshworthItem2'
  },
  {
    content: '腕：屈/伸',
    editKey: 'item3',
    firstKey: 'firstAshworthItem3',
    midKey: 'midAshworthItem3',
    lastKey: 'lastAshworthItem3'
  },
  {
    content: '指：屈/伸',
    editKey: 'item4',
    firstKey: 'firstAshworthItem4',
    midKey: 'midAshworthItem4',
    lastKey: 'lastAshworthItem4'
  },
  {
    content: '髋：前屈/后伸',
    editKey: 'item5',
    firstKey: 'firstAshworthItem5',
    midKey: 'midAshworthItem5',
    lastKey: 'lastAshworthItem5'
  },
  {
    content: '髋：外展/内收',
    editKey: 'item6',
    firstKey: 'firstAshworthItem6',
    midKey: 'midAshworthItem6',
    lastKey: 'lastAshworthItem6'
  },
  {
    content: '膝：屈/伸',
    editKey: 'item7',
    firstKey: 'firstAshworthItem7',
    midKey: 'midAshworthItem7',
    lastKey: 'lastAshworthItem7'
  },
  {
    content: '踝：背屈/跖屈',
    editKey: 'item8',
    firstKey: 'firstAshworthItem8',
    midKey: 'midAshworthItem8',
    lastKey: 'lastAshworthItem8'
  }
]
const assessFormStruct2 = [
  {
    part: '肩',
    content: '前屈',
    editKey: 'item1',
    firstKey: 'firstMMTItem1',
    midKey: 'midMMTItem1',
    lastKey: 'lastMMTItem1',
    rowspan: 4
  },
  {
    part: '肩',
    content: '外展',
    editKey: 'item2',
    firstKey: 'firstMMTItem2',
    midKey: 'midMMTItem2',
    lastKey: 'lastMMTItem2',
    rowspan: 0
  },
  {
    part: '肩',
    content: '内旋',
    editKey: 'item3',
    firstKey: 'firstMMTItem3',
    midKey: 'midMMTItem3',
    lastKey: 'lastMMTItem3',
    rowspan: 0
  },
  {
    part: '肩',
    content: '外旋',
    editKey: 'item4',
    firstKey: 'firstMMTItem4',
    midKey: 'midMMTItem4',
    lastKey: 'lastMMTItem4',
    rowspan: 0
  },
  {
    part: '肘',
    content: '屈',
    editKey: 'item5',
    firstKey: 'firstMMTItem5',
    midKey: 'midMMTItem5',
    lastKey: 'lastMMTItem5',
    rowspan: 2
  },
  {
    part: '肘',
    content: '伸',
    editKey: 'item6',
    firstKey: 'firstMMTItem6',
    midKey: 'midMMTItem6',
    lastKey: 'lastMMTItem6',
    rowspan: 0
  },
  {
    part: '臂',
    content: '旋前',
    editKey: 'item7',
    firstKey: 'firstMMTItem7',
    midKey: 'midMMTItem7',
    lastKey: 'lastMMTItem7',
    rowspan: 2
  },
  {
    part: '臂',
    content: '旋后',
    editKey: 'item8',
    firstKey: 'firstMMTItem8',
    midKey: 'midMMTItem8',
    lastKey: 'lastMMTItem8',
    rowspan: 0
  },
  {
    part: '腕',
    content: '伸',
    editKey: 'item9',
    firstKey: 'firstMMTItem9',
    midKey: 'midMMTItem9',
    lastKey: 'lastMMTItem9',
    rowspan: 2
  },
  {
    part: '腕',
    content: '屈',
    editKey: 'item10',
    firstKey: 'firstMMTItem10',
    midKey: 'midMMTItem10',
    lastKey: 'lastMMTItem10',
    rowspan: 0
  },
  {
    part: '指',
    content: '伸',
    editKey: 'item11',
    firstKey: 'firstMMTItem11',
    midKey: 'midMMTItem11',
    lastKey: 'lastMMTItem11',
    rowspan: 2
  },
  {
    part: '指',
    content: '屈',
    editKey: 'item12',
    firstKey: 'firstMMTItem12',
    midKey: 'midMMTItem12',
    lastKey: 'lastMMTItem12',
    rowspan: 0
  },
  {
    part: '髋',
    content: '屈',
    editKey: 'item13',
    firstKey: 'firstMMTItem13',
    midKey: 'midMMTItem13',
    lastKey: 'lastMMTItem13',
    rowspan: 4
  },
  {
    part: '髋',
    content: '伸',
    editKey: 'item14',
    firstKey: 'firstMMTItem14',
    midKey: 'midMMTItem14',
    lastKey: 'lastMMTItem14',
    rowspan: 0
  },
  {
    part: '髋',
    content: '内收',
    editKey: 'item15',
    firstKey: 'firstMMTItem15',
    midKey: 'midMMTItem15',
    lastKey: 'lastMMTItem15',
    rowspan: 0
  },
  {
    part: '髋',
    content: '外展',
    editKey: 'item16',
    firstKey: 'firstMMTItem16',
    midKey: 'midMMTItem16',
    lastKey: 'lastMMTItem16',
    rowspan: 0
  },
  {
    part: '膝',
    content: '屈',
    editKey: 'item17',
    firstKey: 'firstMMTItem17',
    midKey: 'midMMTItem17',
    lastKey: 'lastMMTItem17',
    rowspan: 2
  },
  {
    part: '膝',
    content: '伸',
    editKey: 'item18',
    firstKey: 'firstMMTItem18',
    midKey: 'midMMTItem18',
    lastKey: 'lastMMTItem18',
    rowspan: 0
  },
  {
    part: '踝',
    content: '背屈',
    editKey: 'item19',
    firstKey: 'firstMMTItem19',
    midKey: 'midMMTItem19',
    lastKey: 'lastMMTItem19',
    rowspan: 2
  },
  {
    part: '踝',
    content: '跖屈',
    editKey: 'item20',
    firstKey: 'firstMMTItem20',
    midKey: 'midMMTItem20',
    lastKey: 'lastMMTItem20',
    rowspan: 0
  }
]
const assessFormStruct3 = [
  {
    part: '肩',
    content: '屈曲',
    levelValue: '0-170',
    leftEditKey: 'leftItem1',
    leftFirstKey: 'leftFirstROMItem1',
    leftMidKey: 'leftMidROMItem1',
    leftLastKey: 'leftLastROMItem1',
    rightEditKey: 'rightItem1',
    rightFirstKey: 'rightFirstROMItem1',
    rightMidKey: 'rightMidROMItem1',
    rightLastKey: 'rightLastROMItem1',
    rowspan: 2
  },
  {
    part: '肩',
    content: '外展',
    levelValue: '0-170',
    leftEditKey: 'leftItem2',
    leftFirstKey: 'leftFirstROMItem2',
    leftMidKey: 'leftMidROMItem2',
    leftLastKey: 'leftLastROMItem2',
    rightEditKey: 'rightItem2',
    rightFirstKey: 'rightFirstROMItem2',
    rightMidKey: 'rightMidROMItem2',
    rightLastKey: 'rightLastROMItem2',
    rowspan: 0
  },
  {
    part: '肘',
    content: '屈曲',
    levelValue: '0-135/150',
    leftEditKey: 'leftItem3',
    leftFirstKey: 'leftFirstROMItem3',
    leftMidKey: 'leftMidROMItem3',
    leftLastKey: 'leftLastROMItem3',
    rightEditKey: 'rightItem3',
    rightFirstKey: 'rightFirstROMItem3',
    rightMidKey: 'rightMidROMItem3',
    rightLastKey: 'rightLastROMItem3',
    rowspan: 1
  },
  {
    part: '腕',
    content: '掌屈/背伸',
    levelValue: '0-80/0-70',
    leftEditKey: 'leftItem4',
    leftFirstKey: 'leftFirstROMItem4',
    leftMidKey: 'leftMidROMItem4',
    leftLastKey: 'leftLastROMItem4',
    rightEditKey: 'rightItem4',
    rightFirstKey: 'rightFirstROMItem4',
    rightMidKey: 'rightMidROMItem4',
    rightLastKey: 'rightLastROMItem4',
    rowspan: 1
  },
  {
    part: '指',
    content: '掌指屈曲',
    levelValue: '0-90',
    leftEditKey: 'leftItem5',
    leftFirstKey: 'leftFirstROMItem5',
    leftMidKey: 'leftMidROMItem5',
    leftLastKey: 'leftLastROMItem5',
    rightEditKey: 'rightItem5',
    rightFirstKey: 'rightFirstROMItem5',
    rightMidKey: 'rightMidROMItem5',
    rightLastKey: 'rightLastROMItem5',
    rowspan: 2
  },
  {
    part: '指',
    content: '指间屈曲',
    levelValue: '0-110',
    leftEditKey: 'leftItem6',
    leftFirstKey: 'leftFirstROMItem6',
    leftMidKey: 'leftMidROMItem6',
    leftLastKey: 'leftLastROMItem6',
    rightEditKey: 'rightItem6',
    rightFirstKey: 'rightFirstROMItem6',
    rightMidKey: 'rightMidROMItem6',
    rightLastKey: 'rightLastROMItem6',
    rowspan: 0
  },
  {
    part: '髋',
    content: '屈曲',
    levelValue: '0-120',
    leftEditKey: 'leftItem7',
    leftFirstKey: 'leftFirstROMItem7',
    leftMidKey: 'leftMidROMItem7',
    leftLastKey: 'leftLastROMItem7',
    rightEditKey: 'rightItem7',
    rightFirstKey: 'rightFirstROMItem7',
    rightMidKey: 'rightMidROMItem7',
    rightLastKey: 'rightLastROMItem7',
    rowspan: 4
  },
  {
    part: '髋',
    content: '伸展',
    levelValue: '0-30',
    leftEditKey: 'leftItem8',
    leftFirstKey: 'leftFirstROMItem8',
    leftMidKey: 'leftMidROMItem8',
    leftLastKey: 'leftLastROMItem8',
    rightEditKey: 'rightItem8',
    rightFirstKey: 'rightFirstROMItem8',
    rightMidKey: 'rightMidROMItem8',
    rightLastKey: 'rightLastROMItem8',
    rowspan: 0
  },
  {
    part: '髋',
    content: '外展',
    levelValue: '0-40',
    leftEditKey: 'leftItem9',
    leftFirstKey: 'leftFirstROMItem9',
    leftMidKey: 'leftMidROMItem9',
    leftLastKey: 'leftLastROMItem9',
    rightEditKey: 'rightItem9',
    rightFirstKey: 'rightFirstROMItem9',
    rightMidKey: 'rightMidROMItem9',
    rightLastKey: 'rightLastROMItem9',
    rowspan: 0
  },
  {
    part: '髋',
    content: '内收',
    levelValue: '0-35',
    leftEditKey: 'leftItem10',
    leftFirstKey: 'leftFirstROMItem10',
    leftMidKey: 'leftMidROMItem10',
    leftLastKey: 'leftLastROMItem10',
    rightEditKey: 'rightItem10',
    rightFirstKey: 'rightFirstROMItem10',
    rightMidKey: 'rightMidROMItem10',
    rightLastKey: 'rightLastROMItem10',
    rowspan: 0
  },
  {
    part: '膝',
    content: '屈曲',
    levelValue: '0-135',
    leftEditKey: 'leftItem11',
    leftFirstKey: 'leftFirstROMItem11',
    leftMidKey: 'leftMidROMItem11',
    leftLastKey: 'leftLastROMItem11',
    rightEditKey: 'rightItem11',
    rightFirstKey: 'rightFirstROMItem11',
    rightMidKey: 'rightMidROMItem11',
    rightLastKey: 'rightLastROMItem11',
    rowspan: 1
  },
  {
    part: '踝',
    content: '背屈/跖屈',
    levelValue: '0-15/0-50',
    leftEditKey: 'leftItem12',
    leftFirstKey: 'leftFirstROMItem12',
    leftMidKey: 'leftMidROMItem12',
    leftLastKey: 'leftLastROMItem12',
    rightEditKey: 'rightItem12',
    rightFirstKey: 'rightFirstROMItem12',
    rightMidKey: 'rightMidROMItem12',
    rightLastKey: 'rightLastROMItem12',
    rowspan: 1
  }
]
const assessFormStruct4 = [
  {
    project: '布氏分级',
    subProject: '上肢',
    projectKey: 'brunnstrom',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 3,
    controlType: 'radio',
    options: brunnstromTypeList
  },
  {
    project: '布氏分级',
    subProject: '手',
    projectKey: 'brunnstrom',
    editKey: 'item2',
    firstKey: 'firstItem2',
    midKey: 'midItem2',
    lastKey: 'lastItem2',
    rowspan: 0,
    controlType: 'radio',
    options: brunnstromTypeList
  },
  {
    project: '布氏分级',
    subProject: '下肢',
    projectKey: 'brunnstrom',
    editKey: 'item3',
    firstKey: 'firstItem3',
    midKey: 'midItem3',
    lastKey: 'lastItem3',
    rowspan: 0,
    controlType: 'radio',
    options: brunnstromTypeList
  },
  {
    project: 'Holder步行',
    projectKey: 'walking',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 1,
    controlType: 'radio',
    options: zeroToSixList.slice(0, 6)
  },
  {
    project: '言语功能',
    projectKey: 'language',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 1,
    controlType: 'radio',
    options: zeroToSixList.slice(0, 6)
  },
  {
    project: '洼田饮水',
    projectKey: 'drinking',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 1,
    controlType: 'radio',
    options: zeroToSixList.slice(1, 6)
  },
  {
    project: '手功能',
    projectKey: 'hand',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 1,
    controlType: 'radio',
    options: handTypeList
  },
  {
    project: '坐位平衡',
    projectKey: 'sitting',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 1,
    controlType: 'radio',
    options: sittingTypeList
  },
  {
    project: '立位平衡',
    projectKey: 'standing',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 1,
    controlType: 'radio',
    options: standingTypeList
  },
  {
    project: 'mRS',
    projectKey: 'mrs',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 1,
    controlType: 'radio',
    options: zeroToSixList
  },
  {
    project: 'MAS',
    subProject: '仰卧位到健侧位0-6',
    projectKey: 'mas',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 9,
    controlType: 'input',
    min: 0,
    max: 6
  },
  {
    project: 'MAS',
    subProject: '从仰卧位到床边坐0-6',
    projectKey: 'mas',
    editKey: 'item2',
    firstKey: 'firstItem2',
    midKey: 'midItem2',
    lastKey: 'lastItem2',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 6
  },
  {
    project: 'MAS',
    subProject: '坐位平衡0-6',
    projectKey: 'mas',
    editKey: 'item3',
    firstKey: 'firstItem3',
    midKey: 'midItem3',
    lastKey: 'lastItem3',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 6
  },
  {
    project: 'MAS',
    subProject: '从坐到站0-6',
    projectKey: 'mas',
    editKey: 'item4',
    firstKey: 'firstItem4',
    midKey: 'midItem4',
    lastKey: 'lastItem4',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 6
  },
  {
    project: 'MAS',
    subProject: '步行0-6',
    projectKey: 'mas',
    editKey: 'item5',
    firstKey: 'firstItem5',
    midKey: 'midItem5',
    lastKey: 'lastItem5',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 6
  },
  {
    project: 'MAS',
    subProject: '上肢功能0-6',
    projectKey: 'mas',
    editKey: 'item6',
    firstKey: 'firstItem6',
    midKey: 'midItem6',
    lastKey: 'lastItem6',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 6
  },
  {
    project: 'MAS',
    subProject: '手的运动0-6',
    projectKey: 'mas',
    editKey: 'item7',
    firstKey: 'firstItem7',
    midKey: 'midItem7',
    lastKey: 'lastItem7',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 6
  },
  {
    project: 'MAS',
    subProject: '手的精细活动0-6',
    projectKey: 'mas',
    editKey: 'item8',
    firstKey: 'firstItem8',
    midKey: 'midItem8',
    lastKey: 'lastItem8',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 6
  },
  {
    project: 'MAS',
    subProject: '总分48',
    projectKey: 'mas',
    editKey: 'total',
    firstKey: 'firstTotal',
    midKey: 'midTotal',
    lastKey: 'lastTotal',
    rowspan: 0
  },
  {
    project: '巴氏指数',
    subProject: '修饰5',
    projectKey: 'barthel',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 11,
    controlType: 'input',
    min: 0,
    max: 5
  },
  {
    project: '巴氏指数',
    subProject: '洗澡5',
    projectKey: 'barthel',
    editKey: 'item2',
    firstKey: 'firstItem2',
    midKey: 'midItem2',
    lastKey: 'lastItem2',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 5
  },
  {
    project: '巴氏指数',
    subProject: '进食10',
    projectKey: 'barthel',
    editKey: 'item3',
    firstKey: 'firstItem3',
    midKey: 'midItem3',
    lastKey: 'lastItem3',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 10
  },
  {
    project: '巴氏指数',
    subProject: '穿着10',
    projectKey: 'barthel',
    editKey: 'item4',
    firstKey: 'firstItem4',
    midKey: 'midItem4',
    lastKey: 'lastItem4',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 10
  },
  {
    project: '巴氏指数',
    subProject: '大便10',
    projectKey: 'barthel',
    editKey: 'item5',
    firstKey: 'firstItem5',
    midKey: 'midItem5',
    lastKey: 'lastItem5',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 10
  },
  {
    project: '巴氏指数',
    subProject: '小便10',
    projectKey: 'barthel',
    editKey: 'item6',
    firstKey: 'firstItem6',
    midKey: 'midItem6',
    lastKey: 'lastItem6',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 10
  },
  {
    project: '巴氏指数',
    subProject: '如厕10',
    projectKey: 'barthel',
    editKey: 'item7',
    firstKey: 'firstItem7',
    midKey: 'midItem7',
    lastKey: 'lastItem7',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 10
  },
  {
    project: '巴氏指数',
    subProject: '楼梯10',
    projectKey: 'barthel',
    editKey: 'item8',
    firstKey: 'firstItem8',
    midKey: 'midItem8',
    lastKey: 'lastItem8',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 10
  },
  {
    project: '巴氏指数',
    subProject: '行走15',
    projectKey: 'barthel',
    editKey: 'item9',
    firstKey: 'firstItem9',
    midKey: 'midItem9',
    lastKey: 'lastItem9',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 15
  },
  {
    project: '巴氏指数',
    subProject: '转移15',
    projectKey: 'barthel',
    editKey: 'item10',
    firstKey: 'firstItem10',
    midKey: 'midItem10',
    lastKey: 'lastItem10',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 15
  },
  {
    project: '巴氏指数',
    subProject: '总分',
    projectKey: 'barthel',
    editKey: 'total',
    firstKey: 'firstTotal',
    midKey: 'midTotal',
    lastKey: 'lastTotal',
    rowspan: 0
  },
  {
    project: 'MMSE',
    subProject: '定向力10分',
    projectKey: 'mmse',
    editKey: 'item1',
    firstKey: 'firstItem1',
    midKey: 'midItem1',
    lastKey: 'lastItem1',
    rowspan: 11,
    controlType: 'input',
    min: 0,
    max: 10
  },
  {
    project: 'MMSE',
    subProject: '记忆力3分',
    projectKey: 'mmse',
    editKey: 'item2',
    firstKey: 'firstItem2',
    midKey: 'midItem2',
    lastKey: 'lastItem2',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 3
  },
  {
    project: 'MMSE',
    subProject: '注意计算5分',
    projectKey: 'mmse',
    editKey: 'item3',
    firstKey: 'firstItem3',
    midKey: 'midItem3',
    lastKey: 'lastItem3',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 5
  },
  {
    project: 'MMSE',
    subProject: '回忆能力3分',
    projectKey: 'mmse',
    editKey: 'item4',
    firstKey: 'firstItem4',
    midKey: 'midItem4',
    lastKey: 'lastItem4',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 3
  },
  {
    project: 'MMSE',
    subProject: '命名2分',
    projectKey: 'mmse',
    editKey: 'item5',
    firstKey: 'firstItem5',
    midKey: 'midItem5',
    lastKey: 'lastItem5',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 2
  },
  {
    project: 'MMSE',
    subProject: '复述1分',
    projectKey: 'mmse',
    editKey: 'item6',
    firstKey: 'firstItem6',
    midKey: 'midItem6',
    lastKey: 'lastItem6',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 1
  },
  {
    project: 'MMSE',
    subProject: '三步命令3分',
    projectKey: 'mmse',
    editKey: 'item7',
    firstKey: 'firstItem7',
    midKey: 'midItem7',
    lastKey: 'lastItem7',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 3
  },
  {
    project: 'MMSE',
    subProject: '阅读1分',
    projectKey: 'mmse',
    editKey: 'item8',
    firstKey: 'firstItem8',
    midKey: 'midItem8',
    lastKey: 'lastItem8',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 1
  },
  {
    project: 'MMSE',
    subProject: '书写1分',
    projectKey: 'mmse',
    editKey: 'item9',
    firstKey: 'firstItem9',
    midKey: 'midItem9',
    lastKey: 'lastItem9',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 1
  },
  {
    project: 'MMSE',
    subProject: '结构1分',
    projectKey: 'mmse',
    editKey: 'item10',
    firstKey: 'firstItem10',
    midKey: 'midItem10',
    lastKey: 'lastItem10',
    rowspan: 0,
    controlType: 'input',
    min: 0,
    max: 1
  },
  {
    project: 'MMSE',
    subProject: '总分30分',
    projectKey: 'mmse',
    editKey: 'total',
    firstKey: 'firstTotal',
    midKey: 'midTotal',
    lastKey: 'lastTotal',
    rowspan: 0
  }
]
export default {
  name: 'Neurorehabilitation',
  props: {
    formType: {
      type: String,
      default: 'template' // 表单类型：template：模板，edit：评估，view：详情
    },
    patientInfo: {
      type: Object,
      default: () => ({}) // 患者信息
    },
    doctorType: {
      type: String,
      default: 'hospital' // 医生类型：hospital：住院医生，outpatient：门诊医生，therapists：治疗师
    },
    assessInfo: {
      type: Object,
      default: () => ({}) // 评定表信息
    }
  },
  data() {
    return {
      typeList,
      tensionValueList,
      unarmedValueList,
      assessFormStruct1,
      assessFormStruct2,
      assessFormStruct3,
      assessFormStruct4,
      selfFormData: {},
      rules: {
        estimateType: [
          { required: true, message: '请选择评定阶段', trigger: 'change' }
        ],
        tensionType: [
          { required: true, message: '请选择肌张力检测侧', trigger: 'change' }
        ],
        unarmedType: [
          { required: true, message: '请选择徒手肌力检测侧', trigger: 'change' }
        ],
        bruseType: [
          { required: true, message: '请选择布氏分级评定', trigger: 'change' }
        ],
        ashworth: [
          { validator: this.validateAshworth, trigger: 'change' }
        ],
        mmt: [
          { validator: this.validateMMT, trigger: 'change' }
        ],
        rom: [
          { validator: this.validateROM, trigger: 'change' }
        ],
        brunnstrom: [
          { validator: this.validateBrunnstrom, trigger: 'change' }
        ]
      },
      firstAssess: true,
      validItems: []
    }
  },
  computed: {
    patientStruct() {
      if (this.formType === 'edit') {
        if (['hospital', 'therapists'].includes(this.doctorType)) {
          return [{
            label: '姓名',
            key: 'patientName'
          }, {
            label: '病区',
            key: 'sickRegion'
          }, {
            label: '床号',
            key: 'bedNum'
          }, {
            label: '住院号',
            key: 'admissionNum'
          }]
        } else {
          return [{
            label: '姓名',
            key: 'patientName'
          }, {
            label: '门诊号',
            key: 'admissionNum'
          }]
        }
      } else if (this.formType === 'view') {
        const struct = [{
          label: '姓名',
          key: 'patientName'
        }, {
          label: '性别',
          key: 'genderName'
        }, {
          label: '年龄',
          key: 'age',
          unit: '岁'
        }, {
          label: '科室',
          key: 'departmentName'
        }]
        if (['hospital', 'therapists'].includes(this.doctorType)) {
          return [
            ...struct,
            {
              label: '床号',
              key: 'bedNum'
            }, {
              label: '住院号',
              key: 'admissionNum'
            }
          ]
        } else {
          return [
            ...struct,
            {
              label: '门诊号',
              key: 'admissionNum'
            }
          ]
        }
      } else {
        return [{
          label: '姓名',
          key: 'patientName'
        }, {
          label: '门诊号/住院号',
          key: 'outpatientNo'
        }]
      }
    }
  },
  watch: {
    assessInfo: function(val) {
      this.initFormData()
    }
  },
  created() {
    this.initFormData()
  },
  methods: {
    initTableData(currentAssessInfo, data, tableList, structList, findFunc, isEdit) {
      if (tableList && tableList.length) {
        data === null && (data = {})
        tableList.forEach(item => {
          const assess = structList.find(assess => findFunc(assess, item))
          if (!assess) {
            return
          }
          if (isEdit) {
            data[assess.editKey] = parseFloat(item.partsValue)
          } else {
            switch (currentAssessInfo.estimateType) {
              case 1:
                data[assess.firstKey] = item.partsValue
                break
              case 2:
                data[assess.midKey] = item.partsValue
                break
              case 3:
                data[assess.lastKey] = item.partsValue
                break
            }
          }
        })
      }
      return data
    },
    initRomData(currentAssessInfo, rom, isEdit) {
      if (currentAssessInfo.jointMobilityList && currentAssessInfo.jointMobilityList.length) {
        rom === null && (rom = {})
        currentAssessInfo.jointMobilityList.forEach(item => {
          const assess = assessFormStruct3.find(assess => item.partsName.endsWith(assess.part + '：' + assess.content))
          if (!assess) {
            return
          }
          if (item.partsName.startsWith('左侧：')) {
            if (isEdit) {
              rom[assess.leftEditKey] = item.partsValue
            } else {
              switch (currentAssessInfo.estimateType) {
                case 1:
                  rom[assess.leftFirstKey] = item.partsValue
                  break
                case 2:
                  rom[assess.leftMidKey] = item.partsValue
                  break
                case 3:
                  rom[assess.leftLastKey] = item.partsValue
                  break
              }
            }
          } else if (item.partsName.startsWith('右侧：')) {
            if (isEdit) {
              rom[assess.rightEditKey] = item.partsValue
            } else {
              switch (currentAssessInfo.estimateType) {
                case 1:
                  rom[assess.rightFirstKey] = item.partsValue
                  break
                case 2:
                  rom[assess.rightMidKey] = item.partsValue
                  break
                case 3:
                  rom[assess.rightLastKey] = item.partsValue
                  break
              }
            }
          }
        })
      }
      return rom
    },
    initBrunnstromData(currentAssessInfo, brunnstrom, isEdit) {
      if (currentAssessInfo.bruseList && currentAssessInfo.bruseList.length) {
        brunnstrom === null && (brunnstrom = {})
        currentAssessInfo.bruseList.forEach(item => {
          const assess = assessFormStruct4.find(assess => {
            const projectName = this.getProjectName(assess)
            return projectName === item.partsName
          })
          if (!assess) {
            return
          }
          if (!brunnstrom[assess.projectKey]) {
            brunnstrom[assess.projectKey] = {}
          }
          if (isEdit) {
            brunnstrom[assess.projectKey][assess.editKey] = parseFloat(item.partsValue)
          } else {
            switch (currentAssessInfo.estimateType) {
              case 1:
                brunnstrom[assess.projectKey][assess.firstKey] = item.partsValue
                break
              case 2:
                brunnstrom[assess.projectKey][assess.midKey] = item.partsValue
                break
              case 3:
                brunnstrom[assess.projectKey][assess.lastKey] = item.partsValue
                break
            }
          }
        })
      }
      return brunnstrom
    },
    initFormData() {
      this.firstAssess = true
      this.selfFormData = Object.assign(initDefaultForm(), this.assessInfo)
      const mainAssessInfo = this.assessInfo
      let ashworth = null
      let mmt = null
      let rom = null
      let brunnstrom = {}
      ashworth = this.initTableData(mainAssessInfo, ashworth, mainAssessInfo.tensionList, assessFormStruct1, (assess, item) => assess.content === item.partsName, true)
      mmt = this.initTableData(mainAssessInfo, mmt, mainAssessInfo.unarmedList, assessFormStruct2, (assess, item) => (assess.part + '：' + assess.content) === item.partsName, true)
      rom = this.initRomData(mainAssessInfo, rom, true)
      brunnstrom = this.initBrunnstromData(mainAssessInfo, brunnstrom, true)

      if (mainAssessInfo.evaluateDetail && mainAssessInfo.evaluateDetail.length) {
        this.firstAssess = false
        let stageList = [1, 2, 3]
        mainAssessInfo.evaluateDetail.forEach(evaluate => {
          stageList = stageList.filter(item => item !== evaluate.estimateType)
          this.selfFormData['evaluateUser' + evaluate.estimateType] = evaluate.evaluateUser
          this.selfFormData['evaluateTime' + evaluate.estimateType] = moment(evaluate.evaluateTime).format('YYYY-MM-DD')
          this.selfFormData.diagnosticInfo = evaluate.diagnosticInfo
          this.selfFormData.estimateType = evaluate.estimateType
          this.selfFormData.tensionType = evaluate.tensionType
          this.selfFormData.unarmedType = evaluate.unarmedType
          this.selfFormData.bruseType = evaluate.bruseType
          ashworth = this.initTableData(evaluate, ashworth, evaluate.tensionList, assessFormStruct1, (assess, item) => assess.content === item.partsName, false)
          mmt = this.initTableData(evaluate, mmt, evaluate.unarmedList, assessFormStruct2, (assess, item) => (assess.part + '：' + assess.content) === item.partsName, false)
          rom = this.initRomData(evaluate, rom, false)
          brunnstrom = this.initBrunnstromData(evaluate, brunnstrom, false)
        })
        if (stageList.length === 1) {
          this.selfFormData.estimateType = stageList[0]
        }
      }

      if (ashworth) {
        this.selfFormData.ashworth = ashworth
      }
      if (mmt) {
        this.selfFormData.mmt = mmt
      }
      if (rom) {
        this.selfFormData.rom = rom
      }

      this.selfFormData = Object.assign(this.selfFormData, brunnstrom)
    },
    getLabelByValue(list, val) {
      const item = list.find(item => item.value === parseFloat(val))
      return item ? item.label : ''
    },
    calcTotal() {
      const calcItems = ['mas', 'barthel', 'mmse']
      calcItems.forEach(item => {
        let total = 0
        Object.keys(this.selfFormData[item]).forEach(key => {
          if (key.startsWith('item')) {
            total += this.selfFormData[item][key] ? parseFloat(this.selfFormData[item][key]) : 0
          }
        })
        this.selfFormData[item]['total'] = total
      })
    },
    getProjectName(item) {
      return item.subProject ? item.project + '：' + item.subProject : item.project
    },
    getFormData() {
      return new Promise((resolve, reject) => {
        this.$refs.assessForm.validate((valid) => {
          if (valid) {
            const tensionList = []
            this.assessFormStruct1.forEach(assess => {
              tensionList.push({
                partsName: assess.content,
                partsValue: this.selfFormData.ashworth[assess.editKey]
              })
            })

            const unarmedList = []
            this.assessFormStruct2.forEach(assess => {
              unarmedList.push({
                partsName: assess.part + '：' + assess.content,
                partsValue: this.selfFormData.mmt[assess.editKey]
              })
            })

            const jointMobilityList = []
            this.assessFormStruct3.forEach(assess => {
              jointMobilityList.push({
                partsName: '左侧：' + assess.part + '：' + assess.content,
                partsValue: this.selfFormData.rom[assess.leftEditKey].trim()
              })
              jointMobilityList.push({
                partsName: '右侧：' + assess.part + '：' + assess.content,
                partsValue: this.selfFormData.rom[assess.rightEditKey].trim()
              })
            })

            const bruseList = []
            this.assessFormStruct4.forEach(assess => {
              const projectName = this.getProjectName(assess)
              bruseList.push({
                partsName: projectName,
                partsValue: this.selfFormData[assess.projectKey][assess.editKey]
              })
            })

            resolve({
              estimateType: this.selfFormData.estimateType,
              bruseType: this.selfFormData.bruseType,
              tensionType: this.selfFormData.tensionType,
              unarmedType: this.selfFormData.unarmedType,
              diagnosticInfo: this.selfFormData.diagnosticInfo,
              tensionList,
              unarmedList,
              jointMobilityList,
              bruseList
            })
          } else {
            reject('存在未通过表单校验的数据')
            return false
          }
        })
      })
    },
    changeToEstimateList(estimateId, submitForm) {
      const keyList = []
      Object.keys(submitForm).forEach(key => {
        if(submitForm[key]){
          keyList.push({
            key,
            value: JSON.stringify(submitForm[key])
          })
        }
      })
      return JSON.stringify({
        estimateId,
        keyList
      })
    },
    async saveLocalFormData(source, patientId) {
      let data = await this.getFormData();
      const estimateId = 9
      const submitForm = {
        evaluateSource: source,
        ...data
      }
      localStorage.setItem(`estimate_${source}_${patientId}_${estimateId}`, this.changeToEstimateList(estimateId, submitForm)); 
    },
    isValidateItem(index, direct){
      let existIndex = this.validItems.findIndex(item => item.index == index && item.direct == direct)
      return existIndex >= 0
    },
    validateAshworth(rule, value, callback) {
      for (let index = 1; index <= 8; index++) {
        if (this.selfFormData.ashworth['item' + index] === undefined) {
          callback('请选择' + assessFormStruct1[index - 1].content + '的评估等级')
          return
        }
      }
      callback()
    },
    validateMMT(rule, value, callback) {
      for (let index = 1; index <= 20; index++) {
        if (this.selfFormData.mmt['item' + index] === undefined) {
          callback('请选择' + assessFormStruct2[index - 1].part + '：' + assessFormStruct2[index - 1].content + '的评估等级')
          return
        }
      }
      callback()
    },
    validateLevelValue(value, ruleArr) {
      if (!value) {
        return false
      }
      const valueArray = value.split('/')
      return ruleArr.some((item, index) => {
        const range = item.split('-')
        if (!valueArray[index] || !/^\d+(.[0-9]*){0,1}$/.test(valueArray[index])) {
          return true
        }
        if (range.length === 1) {
          return valueArray[index] !== range[0]
        } else if (range.length === 2) {
          return parseFloat(valueArray[index]) < parseFloat(range[0]) || parseFloat(valueArray[index]) > parseFloat(range[1])
        }
        return false
      })
    },
    validateROM(rule, value, callback) {
      this.validItems = []
      let hasError = false
      for (let index = 1; index <= 12; index++) {
        const limit = assessFormStruct3[index - 1].levelValue
        const limitArr = limit.split('/')
        const leftValue = this.selfFormData.rom['leftItem' + index].trim()
        const rightValue = this.selfFormData.rom['rightItem' + index].trim()
        if (!leftValue) {
          if(!hasError){
            callback('请填写左侧' + assessFormStruct3[index - 1].part + '：' + assessFormStruct3[index - 1].content + '的活动度')
            hasError = true
          }
        } else if (this.validateLevelValue(leftValue, limitArr)) {
          if(!hasError){
            callback('填写的左侧' + assessFormStruct3[index - 1].part + '：' + assessFormStruct3[index - 1].content + '的活动度不符合活动度填写范围')
            hasError = true
          }
        } else {
          this.validItems.push({
            index: index - 1,
            direct: 'left'
          })
        }
        if (!rightValue) {
          if(!hasError){
            callback('请填写右侧' + assessFormStruct3[index - 1].part + '：' + assessFormStruct3[index - 1].content + '的活动度')
            hasError = true
          }
        } else if (this.validateLevelValue(rightValue, limitArr)) {
          if(!hasError){
            callback('填写的右侧' + assessFormStruct3[index - 1].part + '：' + assessFormStruct3[index - 1].content + '的活动度不符合活动度填写范围')
            hasError = true
          }
        } else {
          this.validItems.push({
            index: index - 1,
            direct: 'right'
          })
        }
      }
      if(!hasError){
        callback()
      }
    },
    validateBrunnstrom(rule, value, callback) {
      assessFormStruct4.forEach(item => {
        if (this.selfFormData[item.projectKey][item.editKey] === undefined) {
          const projectName = this.getProjectName(item)
          if (item.controlType === 'radio') {
            callback('请选择' + projectName + '的评估等级')
          } else {
            callback('请填写' + projectName + '的分值')
          }
          return
        }
      })
      callback()
    }
  }
}
</script>

<style lang="scss" scoped>
@import url('./style.scss');
.neurorehabilitation{
  .form_diagnosis{
    display: flex;
    margin-bottom: 10px;
  }
  .form_table{
    margin: 0;
  }
  .assess_term{
    .el-radio{
      margin-bottom: 10px;
    }
    .term_item{
      display: inline-flex;
      padding-top: 1px;
      .term_name, .term_time, .term_sign{
        width: 240px;
      }
    }
  }
  .score_radio{
    .el-radio{
      margin-right: 10px;
      margin-top: 5px;
      margin-bottom: 5px;
    }
  }
  ::v-deep .el-form-item.is-error .valid_input .el-input__inner {
    border-color: #DCDFE6;
  }
}
</style>
